package cn.ac.cintcm.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import cn.ac.cintcm.util.DateUtil;

@Entity
@Table(name = "HC_TRY")
public class Therapy extends BaseObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3152594833216346665L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@ManyToOne
	@JoinColumn(name="doctor", referencedColumnName="id", nullable=false)
	private User doctor;
	
	@ManyToOne
	@JoinColumn(name="patient", referencedColumnName="id", nullable=false)
	private User patient; // 病人
	
	@OneToMany(fetch=FetchType.EAGER, mappedBy="therapy")
	private List<FeedBack> feedbacks = new ArrayList<FeedBack>();

	@Column
	private Long pid; //续证对应的第一次的诊疗id，如果第一次则为null

	@Column(name = "syn", length = 1000)
	private String synptom; //主诉

	@Column(name = "tp", length = 200)
	private String tonguepulse; //舌脉

	@Column(length = 1000)
	private String formula;//处方
	@Column
	private short dosage=7; //服药贴数
	
	@Column(nullable=false)
	private boolean notify=false; //是否已经短信通知
	@Column
	private Date tdate; //记录时间
	
	@Transient
	private String formulaStr;
	@Transient
	private String dateStr;

	public String getFormula() {
		return formula;
	}
	
	public String getFormulaStr() {
		formulaStr = formula;
		if (formula != null) {
			formulaStr = formulaStr.replaceAll("\r\n|\r|\n", "<br>");
		}
		return formulaStr;
	}
	
	public String getDateStr() {
		dateStr = DateUtil.convertDateToString(tdate);
		return dateStr;
	}

	public void setFormula(String formula) {
		this.formula = formula;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getSynptom() {
		return synptom;
	}

	public void setSynptom(String synptom) {
		this.synptom = synptom;
	}

	public Date getTdate() {
		return tdate;
	}

	public void setTdate(Date tdate) {
		this.tdate = tdate;
	}

	public String getTonguepulse() {
		return tonguepulse;
	}

	public void setTonguepulse(String tonguepulse) {
		this.tonguepulse = tonguepulse;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Therapy other = (Therapy) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

	public Long getPid() {
		return pid;
	}

	public void setPid(Long pid) {
		this.pid = pid;
	}

	public short getDosage() {
		return dosage;
	}

	public void setDosage(short dosage) {
		this.dosage = dosage;
	}

	public boolean getNotify() {
		return notify;
	}

	public void setNotify(boolean notify) {
		this.notify = notify;
	}

	public List<FeedBack> getFeedbacks() {
		return feedbacks;
	}

	public void setFeedbacks(List<FeedBack> feedbacks) {
		this.feedbacks = feedbacks;
	}

	public User getDoctor() {
		return doctor;
	}

	public void setDoctor(User doctor) {
		this.doctor = doctor;
	}

	public User getPatient() {
		return patient;
	}

	public void setPatient(User patient) {
		this.patient = patient;
	}

}
